package com.dljd.javase.t11;


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReaderAndWriterCopyeFile {
    public static void main(String[] args) {
        FileReader reader=null;
        FileWriter writer=null;
        try {
            reader=new FileReader("D:/bg4.jpg");
            writer=new FileWriter("E:/bg4.jpg");
            char[] cs=new char[1024];
            int len=-1;
            while((len=reader.read(cs))!=-1){
                writer.write(cs);
                writer.flush();
                System.out.println(len);
                //System.out.println(new String(cs));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(reader!=null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
